
package com.twb.auth.controller;

import java.util.List;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.twb.auth.entity.twbPost.TwbPost;
import com.twb.auth.entity.twbPost.dto.GetTwbPostByIdDto;
import com.twb.auth.entity.twbPost.dto.SearchTwbPostDto;
import com.twb.auth.entity.twbPost.vo.SaveTwbPostVo;
import com.twb.auth.entity.twbPost.vo.SearchTwbPostVo;
import com.twb.auth.entity.twbPost.vo.UpdateTwbPostByIdVo;
import com.twb.auth.service.ITwbPostService;
import com.twb.core.base.Result;
import com.twb.core.base.controller.BaseController;
import com.twb.core.base.entity.TwbPageInfo;
import com.twb.core.security.annotation.Auth;
import com.twb.core.util.BeanUtils;
import com.twb.core.util.Results;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * @ClassName: TwbPostController
 * @Description: 岗位信息Controller
 * 
 * @author DHL
 * @date 2022-10-24 20:45:59
 */
@RestController
@RequestMapping("/twbPost")
@Api(value = "TwbPostController", tags = "岗位信息")
public class TwbPostController extends BaseController {
  @Autowired
  ITwbPostService twbPostService;

  /**
   * @Title: search
   * @Description: 分页查询
   * @param vo
   * @return
   * @author DHL
   * @date 2022-10-24 20:45:59
   */
  @GetMapping("/search")
  @ApiOperation(value = "分页查询")
  public Result<TwbPageInfo<SearchTwbPostDto>> search(SearchTwbPostVo vo) {
    TwbPageInfo<SearchTwbPostDto> result = twbPostService.searchTwbPost(vo);
    return Results.successWithData(result);
  }

  /**
   * @Title: search
   * @Description: 不分页查询
   * @param vo
   * @return
   * @author DHL
   * @date 2022-10-24 20:45:59
   */
  @Auth(verifyURL = false)
  @GetMapping("/searchList")
  @ApiOperation(value = "不分页查询")
  public Result<List<SearchTwbPostDto>> searchList(SearchTwbPostVo vo) {
    List<SearchTwbPostDto> result = twbPostService.searchTwbPostList(vo);
    return Results.successWithData(result);
  }

  /**
   * @Title: searchSum
   * @Description: 列表查询合计
   * @param vo
   * @return
   * @author DHL
   * @date 2022-10-24 20:45:59
   */
  @Auth(verifyURL = false)
  @GetMapping("/searchSum")
  @ApiOperation(value = "列表查询合计")
  public Result<SearchTwbPostDto> searchSum(SearchTwbPostVo vo) {
    SearchTwbPostDto result = twbPostService.searchTwbPostSum(vo);
    return Results.successWithData(result);
  }

  /**
   * @Title: getById
   * @Description: 根据ID获取详情
   * @param id
   * @return
   * @author DHL
   * @date 2022-10-24 20:45:59
   */
  @GetMapping("/getById")
  @ApiOperation(value = "根据ID获取详情")
  public Result<GetTwbPostByIdDto> getById(
    @NotBlank 
    @RequestParam 
    @ApiParam(value = "主键", name = "id", required = true) 
    String id
  ) {
    TwbPost twbPost = twbPostService.getById(id);
    if (twbPost == null) {
      return Results.failure("数据不存在");
    }
    GetTwbPostByIdDto dto = new GetTwbPostByIdDto();
    BeanUtils.copyNotNullProperties(twbPost, dto);
    return Results.successWithData(dto);
  }

  /**
   * @Title: save
   * @Description: 保存信息
   * @param vo
   * @return
   * @author DHL
   * @date 2022-10-24 20:45:59
   */
  @PostMapping("/save")
  @ApiOperation(value = "保存信息")
  public Result<String> save(@RequestBody @Valid SaveTwbPostVo vo) {
    boolean result = twbPostService.saveTwbPost(vo);
    if (result) {
      return Results.success("保存成功");
    } else {
      return Results.failure("保存失败");
    }
  }

  /**
   * @Title: updateById
   * @Description:更新信息
   * @param vo
   * @return
   * @author DHL
   * @date 2022-10-24 20:45:59
   */
  @PutMapping("/updateById")
  @ApiOperation(value = "更新信息")
  public Result<String> updateById(@RequestBody @Valid UpdateTwbPostByIdVo vo) {
    boolean result = twbPostService.updateTwbPostById(vo);
    if (result) {
      return Results.success("更新成功");
    } else {
      return Results.failure("更新失败");
    }
  }
  
  /**
   * @Title exportExcel
   * @Description 导出Excel
   * @param vo
   * @param response
   * @throws Exception
   * @author DHL
   * @date 2022-10-24 20:45:59
   */
  @PostMapping("/exportExcel")
  @ApiOperation(value = "导出excel")
  public void exportExcel(@RequestBody SearchTwbPostVo vo, HttpServletResponse response) throws Exception {

    twbPostService.exportExcel(vo, response);
  }

  /**
   * @Title: deleteBatchByIds
   * @Description:批量删除信息
   * @param ids
   * @return
   * @author DHL
   * @date 2022-10-24 20:45:59
   */
  // @Auth(verifyToken = true)
  // @PostMapping("/batchDeleteByIds")
  // @ApiOperation(value = "批量删除信息")
  // public Result<String> deleteBatchByIds(
  //   @NotBlank 
  //   @RequestParam 
  //   @ApiParam(value = "主键集合", name = "ids", required = true
  // ) String ids) {
  //   boolean result = twbPostService.deleteTwbPostByIds(ids);
  //   if (result) {
  //     return Results.success("删除成功");
  //   } else {
  //     return Results.failure("删除失败");
  //   }
  // }

  /**
   * @Title: logicBatchDeleteByIds
   * @Description: 批量逻辑删除信息
   * @param ids
   * @return
   * @author DHL
   * @date 2022-10-24 20:45:59
   */
  @Auth(verifyToken = true)
  @PostMapping("/logicBatchDeleteByIds")
  @ApiOperation(value = "批量逻辑删除信息")
  public Result<String> logicBatchDeleteByIds(
    @NotBlank 
    @RequestParam 
    @ApiParam(value = "主键集合", name = "ids", required = true
  ) String ids) {
    int result = twbPostService.logicBatchDeleteTwbPostByIds(ids);
    if (result > 0) {
      return Results.success("删除成功");
    } else {
      return Results.failure("删除失败");
    }
  }
}
